//
//  NutritionFoodsViewController.swift
//  beegin2
//
//  Created by zsy on 16/3/20.
//  Copyright © 2016年 kszz. All rights reserved.
//

import UIKit

class NutritionFoodsViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{

    @IBOutlet weak var segmentFoods: UISegmentedControl!
    @IBOutlet weak var segmentAttr: UISegmentedControl!
    @IBOutlet weak var foodsTableView: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        foodsTableView.tableFooterView = UIView()
        
        segmentFoods.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor(red: 74 / 255, green: 74 / 255, blue: 74 / 255, alpha: 1)], forState: .Normal)
        segmentFoods.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.whiteColor()], forState: .Selected)
        
        segmentAttr.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor(red: 74 / 255, green: 74 / 255, blue: 74 / 255, alpha: 1)], forState: .Normal)
        segmentAttr.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.whiteColor()], forState: .Selected)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    @IBAction func leftNavClick(sender: AnyObject) {
        
        self.navigationController?.popViewControllerAnimated(true)
    }
    @IBAction func segmentValueChanged(sender: UISegmentedControl) {
        
        let segmentFoodsTinColor = [
        UIColor(red: 54 / 255, green: 188 / 255, blue: 155 / 255, alpha: 255 / 255),
        UIColor(red: 246 / 255, green: 187 / 255, blue: 66 / 255, alpha: 255 / 255),
        UIColor(red: 215 / 255, green: 112 / 255, blue: 173 / 255, alpha: 255 / 255),
        UIColor(red: 233 / 255, green: 87 / 255, blue: 63 / 255, alpha: 255 / 255)]
        
        let segmentAttrColor = [
            UIColor(red: 72 / 255, green: 207 / 255, blue: 173 / 255, alpha: 255 / 255),
            UIColor(red: 255 / 255, green: 206 / 255, blue: 84 / 255, alpha: 255 / 255),
            UIColor(red: 236 / 255, green: 135 / 255, blue: 192 / 255, alpha: 255 / 255),
            UIColor(red: 252 / 255, green: 110 / 255, blue: 80 / 255, alpha: 255 / 255)]
        
        if sender.tag == 11{
            
            segmentFoods.tintColor = segmentFoodsTinColor[sender.selectedSegmentIndex]
            segmentAttr.tintColor = segmentFoodsTinColor[sender.selectedSegmentIndex]
            segmentAttr.backgroundColor = segmentAttrColor[sender.selectedSegmentIndex]
        }
            
    }

    // MARK: - UITableViewDelegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        
        if indexPath.section == 0 && indexPath.row == 0{
            
            //self.performSegueWithIdentifier("showMilkBrandSegue", sender: self)
        }
        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
    
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        
        return nil
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 4
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 0
    }
    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let identifier = "nutrFoodsCell"
        let cell = tableView.dequeueReusableCellWithIdentifier(identifier , forIndexPath: indexPath)
        
        if let imageView = cell.viewWithTag(11) as? UIImageView{
            
            imageView.layer.cornerRadius = imageView.frame.width / 2
        }
        
        return cell
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
